package com.demo.api.interceptor.user;

import java.util.Collections;
import java.util.List;

/**
 * @author Tan-Bowen
 * @version 1.0
 * @description TODO
 * @date 2021/8/26 9:52
 */
public class AuthUserInfo {

    private static final ThreadLocal<UserInfo> userInfo = new ThreadLocal<>();

    public static UserInfo getUser() {
        return userInfo.get();
    }

    public static void setUserInfo(UserInfo user) {
        userInfo.set(user);
    }

    public static void clearUser() {
        userInfo.remove();
    }

    /**
     * @author Tan-Bowen
     * @description TODO 当前登录用户id
     * @date 2021/9/2 17:10
     * @param []
     * @paramType []
     * @return java.lang.Long
     */
    public static Long getUserId() {
        UserInfo user = getUser();
        if (user != null) {
            return user.getUserId();
        }
        return 0L;
    }

    /**
     * @author Tan-Bowen
     * @description TODO 当前部门和所有下级部门集合 （超级管理员则为空集合）
     * @date 2021/9/2 17:10
     * @param []
     * @paramType []
     * @return java.util.List<java.lang.Long>
     */
    public static List<Long> getDeptIds() {
        UserInfo user = getUser();
        if (user != null) {
            return user.getDeptIds();
        }
        return Collections.emptyList();
    }


}
